﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using IDAL;

namespace DAL
{
    public class D_CustomerCom : IDAL.ICustomerCom
    {
        WishDayEntities _e;
        public D_CustomerCom()
        {
            _e = new WishDayEntities();
        }
        public void Add(CustomerCom obj)
        {
            _e.CustomerCom.Add(obj);
            _e.SaveChanges();
        }

        public void Delete(int id)
        {
            var data = _e.CustomerCom.Find(id);
            _e.CustomDetails.Remove(_e.CustomDetails.Find(data.CDetailsID));
            _e.CustomerCom.Remove(_e.CustomerCom.Find(id));
            _e.SaveChanges();
        }

        public CustomerCom FindById(int id)
        {
            return _e.CustomerCom.Find(id);
        }

        public List<CustomerCom> GetAll()
        {
            return _e.CustomerCom.ToList();
        }

        public void Update(int id, CustomerCom obj)
        {
            var data = _e.CustomerCom.Find(id);
            data.CDetailsID = obj.CDetailsID;
            data.TemplateID = obj.TemplateID;
            _e.SaveChanges();
        }
    }
}
